import java.util.HashSet;
import java.util.Set;

public class Solution744 {
    public char nextGreatestLetter(char[] letters, char target) {
        Set<Character> set=new HashSet<>();
        for (char letter : letters) {
            set.add(letter);
        }
        for (int i=target+1;i<='z';i++){
            if ( set.contains((char)i)){
                return (char)i;
            }
        }
        for (int i='a';i<=target;i++){
            if ( set.contains((char)i)){
                return (char)i;
            }
        }
        return ' ';
    }

    public static void main(String[] args) {
        System.out.println(new Solution744().nextGreatestLetter(new char[]{'c','f','j'},'a'));
    }
}
